package org.pentaho.cubic.client.perspective.tabs;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;

import com.google.gwt.user.client.ui.NamedFrame;
import com.google.gwt.user.client.ui.TabLayoutPanel;

public class CubicTabLayoutPanel extends TabLayoutPanel {

	private static CubicTabLayoutPanel instance;

	public CubicTabLayoutPanel() {
		super(28, Unit.PX);

		TabWorkspace workspace = new TabWorkspace();
		CubicTabBarWidget t1 = new CubicTabBarWidget("Workspace", "Student BI Workspace", this, workspace, false);
		this.add(workspace, t1);
	}

	public void addTab(String text, String title, String url) {
		String reviseUrl = GWT.getHostPageBaseURL().replace("/pentaho/", "") + url;
		NamedFrame content = new NamedFrame("" + System.currentTimeMillis());
		content.setUrl(reviseUrl);
		CubicTabBarWidget bar = new CubicTabBarWidget(text, title, this, content, true);

		this.add(content, bar);
		this.selectTab(content);
	}

	public static CubicTabLayoutPanel getInstance(){
		if (instance == null) {
			instance = new CubicTabLayoutPanel();
		}
		return instance;
	}

	public void viewWorkspace() {
		this.selectTab(0);
	}
	
	public NamedFrame getSelectedTab()
	{
		return this.getSelectedTab();
	}
	
}